using System;
using System.Linq.Expressions;

namespace Ioc.Kernel.LifeStyles
{
    public abstract class DefaultLifeStyleStrategy : ILifeStyleStrategy
    {
        #region ILifecycleStrategy Members

        /// <summary>
        /// Musts the instanciate.
        /// </summary>
        /// <returns></returns>
        public virtual bool MustInstanciate()
        {
            return true;
        }

        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <returns></returns>
        public virtual Expression GetExpression(Type className)
        {
            return null;
        }

        /// <summary>
        /// Sets the expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        public virtual void SetExpression(Expression expression) {}

        #endregion

        #region Disposing

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        public abstract void Dispose(bool disposing);

        /// <summary>
        /// Releases unmanaged resources and performs other cleanup operations before the
        /// <see cref="DefaultLifeStyleStrategy"/> is reclaimed by garbage collection.
        /// </summary>
        ~DefaultLifeStyleStrategy()
        {
            Dispose(false);
        }

        #endregion
    }
}